package com.lvy.hczn.front.system.service.impl;

import java.util.List;

import cn.hutool.core.util.StrUtil;
import com.lvy.hczn.front.common.exception.UtilException;
import com.lvy.hczn.front.common.utils.DateUtils;
import com.lvy.hczn.front.system.domain.business.DataExceptionDetail;
import com.lvy.hczn.front.system.domain.business.dto.WarehousingEntryDto;
import com.lvy.hczn.front.system.service.DataExceptionDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.lvy.hczn.front.system.mapper.DataExceptionDetailMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lvy.hczn.front.common.core.text.Convert;

/**
 * Service业务层处理
 *
 * @author ruoyi
 * @date 2023-07-04
 */
@Service
public class DataExceptionDetailServiceImpl extends ServiceImpl<DataExceptionDetailMapper, DataExceptionDetail> implements DataExceptionDetailService {

    @Autowired
    private DataExceptionDetailMapper dataExceptionDetailMapper;

    /**
     * 查询
     *
     * @param id 主键
     * @return
     */
    @Override
    public DataExceptionDetail selectDataExceptionDetailById(String id) {
        return dataExceptionDetailMapper.selectById(id);
    }

    /**
     * 查询列表
     *
     * @param dataExceptionDetail
     * @return
     */
    @Override
    public List<DataExceptionDetail> selectDataExceptionDetailList(DataExceptionDetail dataExceptionDetail) {
        return dataExceptionDetailMapper.selectDataExceptionDetailList(dataExceptionDetail);
    }

    /**
     * 新增
     *
     * @param dataExceptionDetail
     * @return 结果
     */
    @Override
    public int insertDataExceptionDetail(DataExceptionDetail dataExceptionDetail) {
        return dataExceptionDetailMapper.insert(dataExceptionDetail);
    }

    /**
     * 修改
     *
     * @param dataExceptionDetail
     * @return 结果
     */
    @Override
    public int updateDataExceptionDetail(DataExceptionDetail dataExceptionDetail) {
        return dataExceptionDetailMapper.updateById(dataExceptionDetail);
    }

    /**
     * 批量删除
     *
     * @param ids 需要删除的主键
     * @return 结果
     */
    @Override
    public int deleteDataExceptionDetailByIds(String ids) {
        String[] idArray = Convert.toStrArray(ids);
        for (String id : idArray) {
            dataExceptionDetailMapper.deleteById(id);
        }
        return idArray.length;
    }

    /**
     * 删除信息
     *
     * @param id 主键
     * @return 结果
     */
    @Override
    public int deleteDataExceptionDetailById(String id) {
        return dataExceptionDetailMapper.deleteById(id);
    }

    /**
     * 根据单据关联主表查详情
     *
     * @param dto
     * @return java.util.List<com.lvy.hczn.front.system.domain.business.DataExceptionDetail>
     * @author yw
     * @date 2023-09-24 16:17:27
     */
    @Override
    public List<DataExceptionDetail> selectListByCodes(WarehousingEntryDto dto) {
        if (StrUtil.isEmpty(dto.getAssociatedOrderCode())) {
            throw new UtilException("单据编号为空");
        }
        if (StrUtil.isEmpty(dto.getServiceCode())) {
            throw new UtilException("业务单号为空");
        }
        if (StrUtil.isEmpty(dto.getDataType())) {
            throw new UtilException("数据类型为空");
        }
        return dataExceptionDetailMapper.selectListByCodes(dto);
    }
}
